#ifndef GRAPH_H_
#define GRAPH_H_

#include "util/trimatrix.h"

/**
 * The segment type dictates what sort of room the generator should place
 * at that point in the graph. Some room types present a particular challenge
 * to the player. Others give an advantage like treasure. Others yet have
 * unique functions for the course of the game (spawn and goal).
 */
typedef enum {
  ST_SPAWN,       /// < player start point
  ST_GOAL,        /// < first player to enter this room wins the game
  ST_CORRIDOR,    /// < unobstrusive pass-through corridor
  ST_MULTIPLEXER, /// < joins and splits paths without leaving choice to the player
  ST_SHORTCUT,    /// < conditional corridor, opens a path once a more advanced path has been visited
  ST_TREASURE,    /// < free treasure up for grabs
  ST_MONSTERS,    /// < fight monsters for treasure & exit
  ST_BOSS,        /// < fight boss monster for treasure & exit
  ST_SWITCHES,    /// < flip switches for treasure & exit
  ST_SOKOBAN,     /// < move boxes for treasure & exit
  ST_MULTIPLAYER  /// < get help from fellow players for treasure or take the exit for free
} SegmentType;

/**
 * A segment has a type and an intensity. The type determines the general
 * segment nature while the intensity is a positive integer that shows to
 * what extent the segment is expressed. Challenge segments with a high
 * number are more difficult while bonus segments with a high number are
 * more helpful. This value can be used to guide the generator towards
 * a balanced dungeon.
 */
typedef struct {
  SegmentType type;
  int intensity;
} Segment;

/** 
 * The dungeon graph is an abstract directed graph representation of the 
 * dungeon consisting of segments (nodes) which are connected together
 * in a way that leaves no segment orphaned. It is used in the first 
 * step of random dungeon generation.
 */
typedef struct {
  Segment* segment;
	int n_segments;
  Trimatrix* path; /// < Connectivity matrix. 1 == connected
} Graph;

void graph_init (Graph* graph, int n_segments);
void graph_cleanup (Graph* graph);

/**
 * Randomly generates the segments for use in the dungeon using the
 * given seed. In a networked game, this function requires that the
 * random seeds are synchronized across all clients first.
 * Connects the segments to make the full dungeon.
 */
void graph_generate (Graph* graph, int n_players, unsigned int seed);

#endif
 
